#!/bin/sh
PROJECT=$1
PORT=$2

if [ -z "$1" ];then
echo "第1个参数项目名称不能为空：sh init.sh 项目名 端口号 "
exit
fi

if [ -z "$2" ];then
echo "第2个参数端口号不能为空：sh init.sh 项目名 端口号"
exit
fi

if [ -n "$2" ];then
 if [ "$2" -gt 0 ] 2>/dev/null ;then
    echo "$2 is number."  
 else
    echo '第2个参数 端口 必须为数字：sh init.sh 项目名 端口号'
 exit
 fi
fi



mkdir -vp ../$PROJECT/{war/,conf/webapps/,logs/}
cp -vr $PWD/bin   ../$PROJECT/bin
cp -vr $PWD/jetty ../$PROJECT/bin

cd ../$PROJECT
PROJECT_HOME=$PWD

#修改jetty.sh
sed -i '1i\if [ -f $NODE_PATH/bin/env.sh ];then' ./bin/jetty/bin/jetty.sh
sed -i '2i\  source $NODE_PATH/bin/env.sh' ./bin/jetty/bin/jetty.sh
sed -i '3i\fi' ./bin/jetty/bin/jetty.sh

#动态生成环境文件
sed -i 's/xxx/'$PROJECT'/g' ./bin/env.sh
sed -i 's/---/'$PORT'/g' ./bin/env.sh
sed -i 's#p_home#'$PROJECT_HOME'#g' ./bin/env.sh
sed -i 's#p_home#'$PROJECT_HOME'#g' ./bin/jettyrestart.sh


